package core;

import com.alibaba.fastjson.JSONObject;
import config.LineEnvironment;
import convert.ClampPackage;
import convert.ClampPackageConverter;
import convert.PackageConverter;
import convert.Transferable;
import exception.PackConvertException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import static convert.PackageBuilder.newPackage;

/**
 * Create Time: 2018年01月25日 20:53
 *
 * @author fin
 */
public class Application {

    private static Logger logger = LogManager.getLogger(Application.class);

    public static void main(String[] args) throws Exception {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("line.xml");
        LineLoader loader = (LineLoader) ctx.getBean("lineLoader");
        loader.run();

        Transferable transferable = newPackage().setAction(1).setVersion(1).setBody(new JSONObject()).build();


        PackageConverter packageConverter = new ClampPackageConverter();
        byte[] b = new byte[0];
        try {
            b = packageConverter.getBytes(transferable);
        } catch (PackConvertException e) {
            logger.error(e);
        }
        try {
            Transferable pack = packageConverter.getPackage(b);
            ClampPackage clampPackage = transferable.cast(ClampPackage.class);
        } catch (PackConvertException e) {
            e.printStackTrace();
        }
    }
}
